#include "../../../libraries/sockets/udp_socket.h"
#include <iostream>
#include <fstream>
#include <string>
#include "../../../config.h"

#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])

{
    if (argc<3)
    {
        cout <<"use this format: ./server IP portno" <<endl;
        exit(1);
    }

    UDP_socket clientUDP;

    string version, letra, p_incog, message, papelera;

    clientUDP.connect(argv[1]);

    if (clientUDP.getServer()==0) clientUDP.error("Unknown host");

    clientUDP.setPortno(atoi(argv[2]));

    cout << "¿Desea ejecutar la versión [E]Española o [I]Inglesa?: ";
    cin >> version;

    clientUDP<<version;

    clientUDP >> p_incog;
    cout << p_incog << endl;


    while(1)
    {
        do
        {
            clientUDP >> message;
            cout << message << endl;
            if(message=="FIN") {return 0;}

        }while(message!="\n Letra?: ");

        cin >> letra;
        clientUDP << letra;

        clientUDP >> p_incog;

        if(p_incog!="nopert")
        {
            cout <<endl<<"    "<<p_incog<<endl;
        }

    }

    return 0;
}
